package com.itheima.tlias84.controller;

import com.itheima.tlias84.dto.SelectLearnerDetailDTO;
import com.itheima.tlias84.mapper.LearnerMapper;
import com.itheima.tlias84.po.InsertLearnerParam;
import com.itheima.tlias84.po.SelectLearnerPageParam;
import com.itheima.tlias84.po.UpdateLearnerParam;
import com.itheima.tlias84.service.LearnerService;
import com.itheima.tlias84.utils.OssUtil;
import com.itheima.tlias84.utils.ResultUtil;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
@CrossOrigin
public class LearnerController {
    @Resource
    LearnerService learnerService;
    //分页查询
    @GetMapping
    public ResultUtil selectLearnerByPage(SelectLearnerPageParam param){
        ResultUtil resultUtil = learnerService.selectLearnerByPage(param);
        return resultUtil;
    }
    //新增学员
    @PostMapping
    public ResultUtil insertLearner(@RequestBody InsertLearnerParam param){
        int flag = learnerService.insertLearner(param);
        return ResultUtil.success(flag);
    }
    //根据id查询
    @GetMapping("/{id}")
    public ResultUtil selectLearnerById(@PathVariable("id") Integer id){
        SelectLearnerDetailDTO dto = learnerService.selectLearnerById(id);
        return ResultUtil.success(dto);
    }
    //修改学员信息
    @PutMapping
    public ResultUtil updateLearner(@RequestBody UpdateLearnerParam param){
        int flag = learnerService.updateLearner(param);
        return ResultUtil.success(flag);
    }
    //批量删除
    @DeleteMapping("/{ids}")
    public ResultUtil batchDeleteLearnerByIds(@PathVariable("ids") List<Integer> ids){
        if (ids.isEmpty()){
            return ResultUtil.fail("请先选择id");
        }
        int flag = learnerService.batchDeleteLearnerByIds(ids);
        return ResultUtil.success(flag);
    }
    //违纪处理
    @PutMapping("/violation/{id}/{score}")
    public ResultUtil vioScore(@PathVariable("id") Integer id, @PathVariable("score") Integer score){
        int flag = learnerService.vioScore(id, score);
        return ResultUtil.success(flag);
    }
//    //批量导入
//    @PutMapping("/import/{clazzId}")
//    public ResultUtil testUpload(@RequestParam("clazzId")Integer clazzId){
//        String upload = OssUtil.upload(clazzId);
//
//    }
}
